import 'package:encrypt/encrypt.dart';

class AESUtil {
  static final String aes_key = "wxblockchainkeylengthinwordsline";

  static String encryptString(String plainText) {
    if (plainText == null || plainText == "") {
      return "";
    }

    var key = Key.fromUtf8(aes_key);
    var iv = IV.fromLength(16);
    var encrypt = Encrypter(AES(key));
    var encrypted = encrypt.encrypt(plainText, iv: iv);

    return encrypted.base64;
  }

  static String decryptString(String encodeText) {
    if (encodeText == null || encodeText == "") {
      return "";
    }

    var key = Key.fromUtf8(aes_key);
    var iv = IV.fromLength(16);
    var encrypt = Encrypter(AES(key));
    var decrypted = encrypt.decrypt64(encodeText, iv: iv);

    return decrypted;
  }
}
